package com.ruoyi.agriculture.zs.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.agriculture.zs.domain.ZsQuestion;
import com.ruoyi.agriculture.zs.mapper.ZsQuestionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.agriculture.zs.mapper.ZsQuestionLikeMapper;
import com.ruoyi.agriculture.zs.domain.ZsQuestionLike;
import com.ruoyi.agriculture.zs.service.IZsQuestionLikeService;

/**
 * 问答点赞Service业务层处理
 *
 * @author zs
 * @date 2025-07-27
 */
@Service
public class ZsQuestionLikeServiceImpl implements IZsQuestionLikeService
{
    @Autowired
    private ZsQuestionLikeMapper zsQuestionLikeMapper;

    @Autowired
    private ZsQuestionMapper zsQuestionMapper;

    /**
     * 查询问答点赞
     *
     * @param zsLikeId 问答点赞主键
     * @return 问答点赞
     */
    @Override
    public ZsQuestionLike selectZsQuestionLikeByZsLikeId(Long zsLikeId)
    {
        return zsQuestionLikeMapper.selectZsQuestionLikeByZsLikeId(zsLikeId);
    }

    /**
     * 查询问答点赞列表
     *
     * @param zsQuestionLike 问答点赞
     * @return 问答点赞
     */
    @Override
    public List<ZsQuestionLike> selectZsQuestionLikeList(ZsQuestionLike zsQuestionLike)
    {
        return zsQuestionLikeMapper.selectZsQuestionLikeList(zsQuestionLike);
    }

    /**
     * 新增问答点赞
     *
     * @param zsQuestionLike 问答点赞
     * @return 结果
     */
    @Override
    public int insertZsQuestionLike(ZsQuestionLike zsQuestionLike)
    {
        ZsQuestion zsQuestion = zsQuestionMapper.selectZsQuestionByZsQuestionId(zsQuestionLike.getZsQuestionId());

        if(zsQuestion==null){
            throw new RuntimeException("问答对象为绑定！");
        }
        zsQuestion.setZsQuestionLikeNum(zsQuestion.getZsQuestionLikeNum() + 1);
        zsQuestionMapper.updateZsQuestion(zsQuestion);

        zsQuestionLike.setUserId(SecurityUtils.getUserId());
        zsQuestionLike.setCreateTime(DateUtils.getNowDate());
        return zsQuestionLikeMapper.insertZsQuestionLike(zsQuestionLike);
    }

    /**
     * 修改问答点赞
     *
     * @param zsQuestionLike 问答点赞
     * @return 结果
     */
    @Override
    public int updateZsQuestionLike(ZsQuestionLike zsQuestionLike)
    {
        zsQuestionLike.setUpdateTime(DateUtils.getNowDate());
        return zsQuestionLikeMapper.updateZsQuestionLike(zsQuestionLike);
    }

    /**
     * 批量删除问答点赞
     *
     * @param zsLikeIds 需要删除的问答点赞主键
     * @return 结果
     */
    @Override
    public int deleteZsQuestionLikeByZsLikeIds(Long[] zsLikeIds)
    {
        return zsQuestionLikeMapper.deleteZsQuestionLikeByZsLikeIds(zsLikeIds);
    }

    /**
     * 删除问答点赞信息
     *
     * @param zsLikeId 问答点赞主键
     * @return 结果
     */
    @Override
    public int deleteZsQuestionLikeByZsLikeId(Long zsLikeId)
    {
        return zsQuestionLikeMapper.deleteZsQuestionLikeByZsLikeId(zsLikeId);
    }
}
